#include "RtpClient.h"
extern "C"{
#include "util/Log.h"
}
/**
  *  @version 1.0
  * Params: BSU_IP + tcp/udp + FileName + FilePath
  *
  * @version 1.1
  * @Params：Server_IP + RtspPort + tcp/udp + URL + QMsgTypeId
  * @Sample: ./BsuClient 172.16.108.200 554 udp rtsp://172.16.108.200:554/H264 1
  *
  * @version 1.2 modify by zgx at 20120408
  * @Params URL + ROOT_PATH + msgId
  * @Sample: ./BsuClient rtsp://172.16.108.200:554/H264 /media/channel1/ 1
  */
extern CRtpClient* gRtpClient;

int main(int argc, char *argv[]) {
    /*
    if (argc != 6) {
        printf("参数错误\n");
        printf("example:\n");
        printf(
                "./BsuClient 172.16.108.200 554 udp rtsp://172.16.108.200:554/H264 1");
        return 0;
    }
    */
    if (argc != 4) {
        printf("参数错误\n");
        printf("example:\n");
        printf("./BsuClient rtsp://172.16.108.200:554/H264 /media/channel1/ 1");
        return 0;
    }

    SetProgrameName("RtpServer");
    WriteLog(LOG_INFO,"RtpServer Start OK!");

    char url[256];
    char serverIP[20],rtpType[10]="udp";
    int rtspPort=554;
    strcpy(url,argv[1]);
    //TODO parse serverIP, rtsp
    std::string mUrl=url;
    std::size_t pos = std::string::npos;
    pos = mUrl.find("//");
    std::string _tmpAddr,strAddr,strPort;
    _tmpAddr.append(mUrl.substr(pos + 2));
    pos = _tmpAddr.find(":");
    strAddr.append(_tmpAddr.substr(0,pos));
    strPort.append(_tmpAddr.substr(pos+1));
    rtspPort = atoi(strPort.c_str());
    strcpy(serverIP,strAddr.c_str());

    printf("serverIP = %s\nrtspPort = %d\n",serverIP,rtspPort);
    gRtpClient=new CRtpClient(serverIP, rtspPort, rtpType, argv[1], argv[2], atol(argv[3]));
    gRtpClient->Run();
    delete gRtpClient;
    return 0;
}
